其他
DID大法:如何在Stata中实现队列DID操作?
数据来源
Yi Chen, Ziying Fan, Xiaomin Gu, and Li-An Zhou. 2020. “Replication Data for: Arrival of Young Talent: The Send-Down Movement and Rural Education in China.” American Economic Association[publisher], Inter-university Consortium for Political and Social Research [distributor]. https://doi.org/10.3886/E119690V1
Standard cohort DID估计
region1990
和省份-出生队列固定效应prov#year_birth
(就是省份与出生队列的交互项,相当于控制了每个省每个出生队列的异质性,这比出生队列固定效应控制的更为细致)外,还在模型中加入了各县基础教育状况与出生队列的交互项c.primary_base#year_birth
和c.junior_base#year_birth
。. reghdfe yedu c.sdy_density#c.treat male han_ethn if rural==1, absorb(region1990 prov#year_birth c.primary_base#year_birth c.junior_base#year_birth) cluster(region1990)
(MWFE estimator converged in 14 iterations)
HDFE Linear regression Number of obs = 2,775,858
Absorbing 4 HDFE groups F( 3, 1767) = 1462.40
Statistics robust to heteroskedasticity Prob > F = 0.0000
R-squared = 0.2934
Adj R-squared = 0.2928
Within R-sq. = 0.1018
Number of clusters (region1990) = 1,768 Root MSE = 2.7831
(Std. Err. adjusted for 1,768 clusters in region1990)
---------------------------------------------------------------------------------------
| Robust
yedu | Coef. Std. Err. t P>|t| [95% Conf. Interval]
----------------------+----------------------------------------------------------------
c.sdy_density#c.treat | 3.237091 .7011438 4.62 0.000 1.861933 4.61225
|
male | 1.874483 .028378 66.05 0.000 1.818825 1.93014
han_ethn | .1500992 .0565311 2.66 0.008 .0392243 .2609742
_cons | 5.436428 .0551559 98.56 0.000 5.32825 5.544606
---------------------------------------------------------------------------------------
Absorbed degrees of freedom:
-------------------------------------------------------------------+
Absorbed FE | Categories - Redundant = Num. Coefs |
---------------------------+---------------------------------------|
region1990 | 1768 1768 0 *|
prov#year_birth | 624 0 624 |
year_birth#c.primary_base | 24 0 24 ?|
year_birth#c.junior_base | 24 0 24 ?|
-------------------------------------------------------------------+
? = number of redundant parameters may be higher
* = FE nested within cluster; treated as redundant for DoF computation
reghdfe
命令,可以看出交互项的系数是3.237091,这与原文报告的估计结果是一致的。其他列的估计方式都是类似的,只需更换一下数据或者是被解释变量即可。Reduced-Form cohort DID估计
地区维度变异:同上。
forvalues y = 1946/1969 {
gen I`y' = sdy_density*[year_birth==`y']
}
. reghdfe yedu I1946-I1969 male han_ethn if rural==1, absorb(region1990 prov#year_birth c.primary_base_older#year_birth c.junior_base_older#year_birth) cluster(region1990)
(MWFE estimator converged in 14 iterations)
HDFE Linear regression Number of obs = 3,082,370
Absorbing 4 HDFE groups F( 26, 1761) = 197.11
Statistics robust to heteroskedasticity Prob > F = 0.0000
R-squared = 0.3101
Adj R-squared = 0.3095
Within R-sq. = 0.1062
Number of clusters (region1990) = 1,762 Root MSE = 2.8137
(Std. Err. adjusted for 1,762 clusters in region1990)
------------------------------------------------------------------------------
| Robust
yedu | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
I1946 | 1.66256 .7684583 2.16 0.031 .1553734 3.169747
I1947 | -.0350028 .7205034 -0.05 0.961 -1.448135 1.378129
I1948 | .3873289 .8108702 0.48 0.633 -1.203041 1.977698
I1949 | -.0806064 .7207926 -0.11 0.911 -1.494306 1.333093
I1950 | .0444851 .7051097 0.06 0.950 -1.338455 1.427425
I1951 | .0476566 .9115992 0.05 0.958 -1.740274 1.835587
I1952 | -.5168174 .8303635 -0.62 0.534 -2.145419 1.111784
I1953 | -1.399235 .8577277 -1.63 0.103 -3.081506 .283037
I1954 | .2770551 .9313479 0.30 0.766 -1.549609 2.103719
I1955 | .8836312 .8897173 0.99 0.321 -.861382 2.628644
I1956 | 1.517669 1.018799 1.49 0.136 -.4805141 3.515853
I1957 | 2.300266 1.016131 2.26 0.024 .3073154 4.293216
I1958 | 2.858782 1.074015 2.66 0.008 .7523023 4.965261
I1959 | 4.254199 1.127633 3.77 0.000 2.042558 6.46584
I1960 | 4.22015 1.221957 3.45 0.001 1.82351 6.616789
I1961 | 3.86647 1.477515 2.62 0.009 .9686016 6.764339
I1962 | 4.990398 1.16422 4.29 0.000 2.706999 7.273797
I1963 | 4.390182 1.066651 4.12 0.000 2.298147 6.482217
I1964 | 3.146871 .984423 3.20 0.001 1.216111 5.077632
I1965 | 3.551206 .9706773 3.66 0.000 1.647405 5.455007
I1966 | 3.329448 .9370527 3.55 0.000 1.491595 5.1673
I1967 | 3.273766 1.006823 3.25 0.001 1.299072 5.248459
I1968 | 4.09358 .9098564 4.50 0.000 2.309068 5.878092
I1969 | 3.144828 1.013811 3.10 0.002 1.156428 5.133227
male | 1.939975 .0275946 70.30 0.000 1.885853 1.994096
han_ethn | .1394096 .055681 2.50 0.012 .0302018 .2486174
_cons | 5.209187 .0551155 94.51 0.000 5.101089 5.317286
------------------------------------------------------------------------------
Absorbed degrees of freedom:
-------------------------------------------------------------------------+
Absorbed FE | Categories - Redundant = Num. Coefs |
---------------------------------+---------------------------------------|
region1990 | 1762 1762 0 *|
prov#year_birth | 754 0 754 |
year_birth#c.primary_base_older | 29 0 29 ?|
year_birth#c.junior_base_older | 29 0 29 ?|
-------------------------------------------------------------------------+
? = number of redundant parameters may be higher
* = FE nested within cluster; treated as redundant for DoF computation
coefplot
。coefplot
命令可以便捷地根据回归结果帮助我们绘制回归系数的取值和置信区间,常用于DID平行趋势检验制图。*-绘图
coefplot, baselevels ///
keep(I19*) ///
vertical ///转置图形
coeflabels(I1946=1946 I1947=1947 I1948=1948 I1949=1949 I1950=1950 ///
I1951=1951 I1952=1952 I1953=1953 I1954=1954 I1955=1955 I1956=1956 ///
I1957=1957 I1958=1958 I1959=1959 I1960=1960 I1961=1961 I1962=1962 ///
I1963=1963 I1964=1964 I1965=1965 I1966=1966 I1967=1967 I1968=1968 ///
I1969=1969) ///
yline(0,lwidth(vthin) lpattern(solid) lcolor(teal)) ///
xline(10,lwidth(vthin) lpattern(solid) lcolor(teal)) ///
ylabel(-4(2)8,labsize(*0.85) angle(0)) xlabel(,labsize(*0.75) angle(45)) ///
ytitle("Coefficients") ///
xtitle("Birth cohort") ///
msymbol(O) msize(small) mcolor(gs1) ///plot样式
addplot(line @b @at,lcolor(gs1) lwidth(medthick)) ///增加点之间的连线
ciopts(recast(rline) lwidth(thin) lpattern(dash) lcolor(gs2)) ///置信区间样式
graphregion(color(white)) //白底
注:图中虚线表示95%置信区间
recast()
括号里的选项,绘制出不同样式的图。需要本文使用的数据和代码的朋友,请在后台对话框内回复关键词“知青”,喜欢还请帮忙点个在看哦!